package org.erp.product.infrastructure.enums;

import lombok.Getter;
import org.erp.product.infrastructure.exception.ProductException;

/**
 * @author libin
 * @version 1.0
 * @description:
 * @date 2025/11/17 9:43
 **/
@Getter
public enum InspectionEventEnum {
    QUALITY(0, "质检"),
    ON_SHELF(1, "上架"),
    OFF_SHELF(2, "下架"),
    TRANSFER(3, "调拨"),
    SELL_CONNECT(4, "销售接驳"),
    INSPECTION_DICKER_CONNECT(5, "质检/溢价接驳"),
    REPAIR_CONNECT(6, "维修接驳"),
    INSPECTION_DICKER_OVERRULE(7, "质检/溢价驳回"),
    SELL_OVERRULE(8, "销售驳回"),
    RETURN_BACK(9, "发起返库"),
    CONFIRM_RETURN(10, "确认返库");

    private final Integer code;
    private final String message;

    InspectionEventEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Integer getCodeByMessage(String message) {
        for (InspectionEventEnum item : InspectionEventEnum.values()) {
            if (item.getMessage().equals(message)) {
                return item.getCode();
            }
        }
        return null;
    }

    public static String getMessageByCode(Integer code) {
        for (InspectionEventEnum item : InspectionEventEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getMessage();
            }
        }
        return null;
    }

    public static InspectionEventEnum getByCode(Integer code) {
        for (InspectionEventEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new ProductException("无效的 inspectionEvent: " + code);
    }

    public static InspectionEventEnum getByMessage(String message) {
        for (InspectionEventEnum value : values()) {
            if (value.getMessage().equals(message)) {
                return value;
            }
        }
        throw new ProductException("无效的 inspectionEvent: " + message);
    }
}
